package com.bobo.demo.Thread.sync;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class UnsafeList {
    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        List<String> safeList = new CopyOnWriteArrayList<String>();

        for (int i = 0; i < 10000; i++) {
            new Thread( () ->{
                list.add(Thread.currentThread().getName());
            }).start();
        }

        for (int i = 0; i < 10000; i++) {
            new Thread( () ->{
                safeList.add(Thread.currentThread().getName());
            }).start();
        }
        System.out.println(list.size());
        System.out.println(safeList.size());
    }

}
